<template>
  <div class="caty-active">
    <el-tabs v-model="activeName" @tab-click="handleClick">
     <el-tab-pane label="" :name="null">
       <span slot="label">
          全部订单<el-badge :value="this.info"></el-badge>
        </span>
     </el-tab-pane>
    <el-tab-pane name="Amount" label="退款">
         <span slot="label" @click="aaa">
          退款<el-badge></el-badge>
        </span>
    </el-tab-pane>
    <el-tab-pane name="GoodAmount">
         <span slot="label" @click="aaa">
          退货退款<el-badge></el-badge>
        </span>
    </el-tab-pane>
    <el-tab-pane name="Change">
         <span slot="label" @click="aaa">
          换货<el-badge></el-badge>
        </span>
    </el-tab-pane>
   </el-tabs>
     <!-- 列表 -->
      <el-table
      :data="list"
      style="width:100%"
      >
      <el-table-column
        prop="mainOrderId"
        label="订单号"
        width="240">
      </el-table-column>
      <el-table-column
        prop="refundAmount"
        label="退款金额"
        width="150">
      </el-table-column>
      <el-table-column
        prop="refundType"
        label="售后类型"
        width="180">
          <template v-slot="{row}">
          {{formatEmployment(row.refundType)}}
        </template>
      </el-table-column>
        <el-table-column
        prop="details[0].refundReason.desc"
        label="申请原因"
        width="180">
      </el-table-column>
        <el-table-column
        prop="remake"
        label="说明"
        width="180">
      </el-table-column>
        <el-table-column
        label="状态"
        width="150">
        <template v-slot="{row}">
          <el-tag
              :type="
                row.status === 'Pass'
                  ? 'success'
                  : 'danger' && row.status === 'Reject'
                  ? 'info':'danger'"
              disable-transitions
            >
          {{formatEmployment(row.status)}}
          </el-tag>
        </template>
      </el-table-column>
        <el-table-column
        prop="details[0].goodStatus"
        label="货物状态"
        width="150">
        <template v-slot="{row}">
          {{formatEmployment(row.details[0].goodStatus)}}
        </template>
 
      </el-table-column>
        <el-table-column
        prop="applyTime"
        label="申请时间"
        width="180">
      </el-table-column>
        <el-table-column
        fixed="right"
        label="操作"
        width="180">
        <template v-slot="{row}">
        <el-button type="text" size="small" @click="xagree(row)" v-if="row.status == 'Approval'">同意</el-button>
        <el-button type="text" size="small" @click="xdown(row)" v-if="row.status == 'Approval'">拒绝</el-button>
        <el-button type="text" size="small" @click="hcomplid(row)">订单详细</el-button>
        </template>
      </el-table-column>
    </el-table>
     <!-- 查看详细组件 -->
      <el-dialog title="订单详细"
      class="acvter"
     :destroy-on-close='true'
     :visible.sync="dialogFormVisib">
     <Windo @close="dialogFormVisib = false" :childata="childata"></Windo>
     </el-dialog>

     <el-pagination
        class="lyx"
      :current-page.sync="q.page"
      :page-size="2"
      :page-sizes="[10, 15, 20]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      >
      </el-pagination>
  </div>
</template>

<script>
import { refund, xhoder, xconsent } from '@/api/roles'
import Windo from './components/windo.vue'
import employeesConst from "@/constant/employees";
const hireTypec = {};
employeesConst.hireTypecer.forEach((item) => {
  hireTypec[item.status] = item.value;
});
employeesConst.hierTypedefch.forEach((item) => {
  hireTypec[item.type] = item.value;
});
employeesConst.hierpdfc.forEach((item) => {
   hireTypec[item.goodStatus] = item.value;
})

export default {
  components: { Windo },
 data () {
    return {
      childata:{},
      dialogFormVisib:false,
      total:0,
      list:[],
      q:{
        index:1,
        size:10,
        refundType:null
      },
      activeName:null,
      info:null
    }
 },
 created(){
    this.loadefch()
 },
 methods:{
  // 获取数据
  async loadefch(){
     const res = await refund(this.q)
     this.list = res.data.data
     this.total = res.data.count-0
     this.loacgher()
  },
  //  未读数
  loacgher(){
       this.info = this.$cookies.get('final')
       
  },
  aaa(){

     },
      handleClick(vall) {
      this.q.refundType = vall.name
      this.loadefch()
    },
    // 同意
    async xagree(row){
        this.$confirm("您确认要同意退货么?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const params = new URLSearchParams(); // 创建URLSearchParams数据对象
          params.append("refundId", row.refundId);
          const res = await xconsent(params);
          this.$cookies.remove('final')  // 删除cookies'final'
          this.loadefch();
          if (res.code !== 200) return this.$message.error(res.msg);
          this.$message.success(res.msg);
        })
        .catch(() => {});
    },
    // 拒绝
    async xdown(row){
     this.$prompt("请输入拒绝原因!", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
       .then(async ({value}) => {
          const params = new URLSearchParams(); // 创建URLSearchParams数据对象
          params.append("refundId", row.refundId);
          params.append("remake", value);
          const res = await xhoder(params);
          this.$cookies.remove('final')   // 删除cookies'final'
          this.loadefch();
          if (res.code !== 200) return this.$message.error(res.msg);
          this.$message.success(res.msg);
        })
        .catch(() => {});
    },
    // 查看退款详细
    hcomplid(row){
       this.dialogFormVisib = true
       this.childata = row
    },
     // 状态
    formatEmployment(code) {
      return hireTypec[code];
    },
    // 分页
    handleCurrentChange(index) {
      this.q.index = index;
      this.loadefch();
    },
    handleSizeChange(size) {
      this.q.size = size;
      this.loadefch();

    },
 }
}
</script>

<style scoped>
.caty-active {
    background-color: #fff;
    padding: 15px;
}
::v-deep .el-dialog{
  width: 450px !important;
  height: 70%;
  overflow: auto;
}
::v-deep .el-tabs__item.is-active{
  color: #ff7144 !important;
}
::v-deep .el-tabs__item:hover {
  color: #ff7144;
}
::v-deep .el-tabs__active-bar{
  background-color: #ff7144;
}
</style>